﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using SmartSpace.Core;
using SmartSpace.Framework;

namespace SsTool
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : System.Windows.Application
    {
        public static IUnityContainer s_unityContainer;

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            s_unityContainer = new UnityContainer();
            UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            section.Configure(s_unityContainer);
        }

        internal static bool Init(string server, string db, string uid, string pwd)
        {
            //s_unityContainer = new UnityContainer();
            //UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
            //section.Configure(s_unityContainer);

            //System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
            //builder.DataSource = server;
            //builder.InitialCatalog = db;
            //builder.UserID = uid;
            //builder.Password = pwd;
            //builder.PersistSecurityInfo = true;
            //string connectionString = builder.ConnectionString;

            return true;
        }

        public static T Get<T>()
        {
            return s_unityContainer.Resolve<T>();
        }
    }
}
